package com.example.weathermvvm.data.network.api

import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory

/**
 *
 * @Author： LJH
 * @Time： 2022/8/11
 * @description：
 */
object ServiceCreator {
    private const val BASE_URL = "http://guolin.tech/"

    private val httpClient = OkHttpClient.Builder()

    private val builder = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(httpClient.build())
            //它会把请求的数据转换为String。默认为ResponseBody
        .addConverterFactory(ScalarsConverterFactory.create())
            //转换为javaBean对象
        .addConverterFactory(GsonConverterFactory.create())

    private val retrofit = builder.build()

    fun <T> create(serviceClass:Class<T>):T = retrofit.create(serviceClass)
}